@extends('Admin.Index.index')
@section('title')
    商品分类
@endsection
@section('content')
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 产品管理 <span class="c-gray en">&gt;</span> 品牌管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="text-c">
        <form class="Huiform" method="post" action="" target="_self">
            <input type="text" placeholder="分类名称" value="" class="input-text" style="width:120px" id="className">

            <span class="select-box" style="width:150px">
                <select class="select" name="brandclass" size="1" id="tag_id">
                    @foreach($tag_list as $vv)
                        <option value="{{$vv->tag_id}}" selected>{{$vv->tag_name}}</option>
                    @endforeach
                </select>
			</span>
            <button type="button" class="btn btn-success" id="add_class" name="" >
                <i class="Hui-iconfont">&#xe600;</i> 添加
            </button>
        </form>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius">
                <i class="Hui-iconfont">&#xe681;</i> 分类列表
            </a>
        </span>
        <span class="r">
            共有数据：<strong>{{$count}}</strong> 条
        </span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-bg table-sort">
            <thead>
            <tr class="text-c ">

                <th width="70">ID</th>
                <th width="70">标签</th>


                <th width="120">分类名称</th>

                <th width="100">操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($list as $v)
                <tr class="text-c">

                    <td>{{$v->c_id}}</td>
                    <td>{{$v->c_name}}</td>


                    <td class="text-c"> {{$v->tag_name}}</td>

                    <td class="f-14 product-brand-manage">
                        <a style="text-decoration:none" onClick="class_edit('品牌编辑','edit_class/{{$v->c_id}}','1')" href="javascript:;" title="编辑">
                            <i class="Hui-iconfont">&#xe6df;</i>修改
                        </a>
                        <a style="text-decoration:none" class="ml-5" onClick="class_del(this,'{{$v->c_id}}')" href="javascript:;" title="删除">
                            <i class="Hui-iconfont">&#xe6e2;</i>删除
                        </a>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        /**
         * 分类名称的初步验证
         */
        $('#className').blur(function () {
            var name = $('#className').val();
            if(name.length == 0)
            {
                layer.msg('分类名称不能为空',{icon:5});
                return false;
            }else if(name.length >10 || name.length  <2)
            {
                layer.msg('请输入2~10位分类名称',{icon:5});
                return false;
            }
            var p = /[*&^%$#@!?]+/;

            if (p.exec(name))
            {
                layer.msg('分类名称不能带符号1',{icon:5});
                return false;
            }
        });

        /**
         * ajax发送
         */
        $('#add_class').click(function () {
            var name = $('#className').val();
//
            if(name.length === 0)
            {
                layer.msg('分类名称不能为空',{icon:5});
                return false;
            }

            var tag_id = $('#tag_id').val();
            layer.load(2);
            $.post('',{name:name,tag_id:tag_id},function (e) {
                console.log(e);
                layer.closeAll('loading');
                if(e.status === 1)
                {
                    layer.msg(e.info,{icon:1,time:1000});
                    window.location.reload();
                }else{
                    layer.msg(e.info,{icon:5});
                }
            })

        });

    });

    /*分类-修改*/
    function class_edit(title,url,id,w,h){
        layer_show(title,url,w,h);
    }

    /*分类-删除*/
    function class_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: 'class_del/'+id,
                dataType: 'json',
                success: function(data){
                    //console.log(data);
                    if (data.status)
                    {
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000});
                    }else {
                        layer.msg('失败!',{icon:5,time:1000});
                    }

                },
                error:function(data) {
                    //console.log(data);
                    console.log(data.msg);
                },
            });
        });
    }
</script>
@endsection